#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <algorithm>

/**
 * 
 * 时间复杂度：
 * x=i^2:O(1)
 * x转n进制数：O(logi)
 * push_back:O(logi)
 * reverse:O(logi)
 * 拷贝构造：O(logi)
 * 检查回文：O(logi)
 * 
 * 总体：ΣO(logi),i=1->300
 * 
 * 空间复杂度：O(log300)
 * (每次for循环数组会释放，最坏的情况是O(log300))
 * 
 * 回文数
 * @return
 */
int main() {

	int n;
	scanf("%d", &n);

	for (int i = 1; i <= 300; i++) {
		int x = i * i;
		std::vector<int> a, b;
		while (x > 0) {
			a.push_back(x % n);
			x /= n;
		}

		b = a;
		std::reverse(b.begin(), b.end());

		if (a == b) {
			x = i;
			b.clear();
			while (x > 0) {
				b.push_back(x % n);
				x /= n;
			}

			for (int i = b.size() - 1; i >= 0; i--) {
				//输出单个字符
				putchar(b[i] <= 9 ? '0' + b[i] : 'A' + b[i] - 10);
			}

			putchar(' ');
			for (int i = 0; i < a.size(); i++) {
				putchar(a[i] <= 9 ? '0' + a[i] : 'A' + a[i] - 10);
			}
			putchar('\n');

		}

	}


	return 0;
}